package com.yhn.bubblevideo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.bubblevideo.admin.service.CollectService;
import com.yhn.bubblevideo.common.model.BaseResponse;
import com.yhn.bubblevideo.common.model.DeleteBatchRequest;
import com.yhn.bubblevideo.common.model.ResultUtils;
import com.yhn.bubblevideo.model.dto.req.collect.CollectAddRequestDTO;
import com.yhn.bubblevideo.model.dto.req.collect.CollectEditRequestDTO;
import com.yhn.bubblevideo.model.dto.req.collect.CollectQueryRequestDTO;
import com.yhn.bubblevideo.model.dto.req.common.DeleteRequest;
import com.yhn.bubblevideo.model.dto.resp.CollectRespDTO;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * @author yhn
 * @version 1.0
 * @description
 * @date 2024/11/24 15:19
 */
@RestController
@RequestMapping("/collect")
public class CollectController {

    @Resource
    private CollectService collectService;

    /**
     * 列表,分页
     */

    @PostMapping("/list")
    @SaCheckLogin
    public BaseResponse<Page<CollectRespDTO>> listCollectPage(@RequestBody @Valid CollectQueryRequestDTO requestParam) {
        Page<CollectRespDTO> page = collectService.queryPage(requestParam);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    public BaseResponse<CollectRespDTO> getCollectInfoById(@PathVariable("id") Long id) {
        CollectRespDTO collect = collectService.getInfoById(id);
        return ResultUtils.success(collect);
    }


    /**
     * 保存
     */
    @PostMapping("/add")
    public BaseResponse<Long> saveCollect(@RequestBody @Valid CollectAddRequestDTO requestParam) {
        Long newId = collectService.saveCollect(requestParam);
        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateCollect(@RequestBody @Valid CollectEditRequestDTO requestParam) {
        boolean result = collectService.updateCollect(requestParam);
        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteCollect(@RequestBody DeleteRequest deleteRequest) {
        boolean result = collectService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    public BaseResponse<Boolean> deleteBatchCollects(@RequestBody DeleteBatchRequest deleteBatchRequest) {
        boolean result = collectService.deleteBatchByIds(deleteBatchRequest.getIds());
        return ResultUtils.success(result);
    }
}
